<?php
class Shop_Model_Observer_AttacheAttribsToAttrSet extends Promotor_Observable_Observer_Abstract {
	public function update(Promotor_Observable_List $list, $attrSetId = null) {
		$rq = $this->getRequest();

		if ((null === ($contenttab = $rq->getPost('contenttab')))) {
			$this->_setStatus(self::NULL);
			return;
		}
		if (!isset($contenttab['attribs'])) {
			$this->_setStatus(self::NULL);
			return;
		}
		
		if (is_array($attrSetId)) {
			$attrSetId = isset($attrSetId['id'])
				? $attrSetId['id']
				: current($attrSetId);
		}

		if (null === $attrSetId) {
			$this->_setStatus(self::NULL);
			return;
		}

		$model = new Shop_Model_AttrsSet();
		$model->attacheAttribsToAttrSet($attrSetId, (array) $contenttab['attribs']);

		$status = $model->getStatus();

		$this->_setStatus($status);
		$this->_setMessages($model->getMessages(false));
		$this->_exception = $model->getExceptions();
	}
}